package com.zlj.response;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 重定向：设置302状态码，设置Location
 * 
 */
@WebServlet("/DServlet")
public class DServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	public  void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		/*
		 * 重定向：
		 * 1、设置Location
		 * 2、发送302状态码
		 */
		
		/*
		response.setHeader("Location", "/servletDemo/CServlet");
		response.setStatus(302);
		*/
		
		/*
		 * 快捷的重定向方法: response.sendRedirect(String Location)
		 */
		//response.sendRedirect("/servletDemo/CServlet");
		response.sendRedirect("http://www.baidu.com");
	}
}
